package com.shelpe.services.scheduler.step;

import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.shelpe.services.scheduler.po.Adgroups;

@Configuration
public class KeywordStepConfiguration {

	 @Autowired
	 private StepBuilderFactory steps;
	 
	 @Bean 
	 public Step keywordStep(@Qualifier("adgroupReader") ItemReader<Adgroups> reader,
			 @Qualifier("keywordProcessor") ItemProcessor<Adgroups, Adgroups> processor,
			 @Qualifier("adgroupWriter") ItemWriter<Adgroups> writer){
 
		 return steps.get("keywordStep")			 
						.<Adgroups, Adgroups> chunk(1)
						.reader(reader)
						.processor(processor)
						.writer(writer)
						.faultTolerant()
						.retry(Exception.class)
						.retryLimit(6)
						.build();
	 }
	 
	 @Bean
	 public Step rptKeywordStep(@Qualifier("adgroupReader") ItemReader<Adgroups> reader,
			 @Qualifier("rptKeywordProcessor") ItemProcessor<Adgroups, Adgroups> processor,
			 @Qualifier("adgroupWriter") ItemWriter<Adgroups> writer){
 
		 return steps.get("rptKeywordStep")			 
						.<Adgroups, Adgroups> chunk(1)
						.reader(reader)
						.processor(processor)
						.writer(writer)
						.faultTolerant()
						.retry(Exception.class)
						.retryLimit(6)
						.build();
	 }
}
